﻿using ProductMonitor.Model;
using ProductMonitor.UserControls;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace ProductMonitor.ViewModel;

public class MainViewModel : INotifyPropertyChanged
{
    private UserControl _userControl;

    public event PropertyChangedEventHandler? PropertyChanged;

    /// <summary>
    /// 初始化环境数据
    /// </summary>
    public MainViewModel()
    {
        #region 初始化环境监控数据
        EnvironmentModels = new List<EnviromentModel>();

        EnvironmentModels.Add(new EnviromentModel { EnName = "光照(Lux)", EnValue = 123 });
        EnvironmentModels.Add(new EnviromentModel { EnName = "噪音(db)", EnValue = 55 });
        EnvironmentModels.Add(new EnviromentModel { EnName = "温度(℃)", EnValue = 80 });
        EnvironmentModels.Add(new EnviromentModel { EnName = "湿度(%)", EnValue = 43 });
        EnvironmentModels.Add(new EnviromentModel { EnName = "PM2.5(m³)", EnValue = 20 });
        EnvironmentModels.Add(new EnviromentModel { EnName = "硫化氢(PPM)", EnValue = 15 });
        EnvironmentModels.Add(new EnviromentModel { EnName = "氮气(PPM)", EnValue = 18 });

        #endregion 
        #region 初始化报警列表

        AlarmList = new List<AlarmModel>();
        AlarmList.Add(new AlarmModel { Num = "01", Msg = "设备温度过高", Time = "2023-11-23 18:34:56", Duration = 7 });
        AlarmList.Add(new AlarmModel { Num = "02", Msg = "车间温度过高", Time = "2023-12-08 20:40:59", Duration = 10 });
        AlarmList.Add(new AlarmModel { Num = "03", Msg = "设备转速过快", Time = "2024-01-05 12:24:34", Duration = 12 });
        AlarmList.Add(new AlarmModel { Num = "04", Msg = "设备气压偏低", Time = "2024-02-04 19:58:00", Duration = 90 });
        #endregion

        #region 初始化设备监控
        DeviceList = new List<DeviceModel>();
        DeviceList.Add(new DeviceModel { DeviceItem = "电能(Kw.h)", Value = 60.8 });
        DeviceList.Add(new DeviceModel { DeviceItem = "电压(V)", Value = 390 });
        DeviceList.Add(new DeviceModel { DeviceItem = "电流(A)", Value = 5 });
        DeviceList.Add(new DeviceModel { DeviceItem = "压差(kpa)", Value = 13 });
        DeviceList.Add(new DeviceModel { DeviceItem = "温度(℃)", Value = 36 });
        DeviceList.Add(new DeviceModel { DeviceItem = "振动(mm/s)", Value = 4.1 });
        DeviceList.Add(new DeviceModel { DeviceItem = "转速(r/min)", Value = 2600 });
        DeviceList.Add(new DeviceModel { DeviceItem = "气压(kpa)", Value = 0.5 });
        #endregion

        #region 初始化雷达数据 
        RaderModels = new List<RaderModel>();
        RaderModels.Add(new RaderModel { ItemName = "排烟风机", Value = 90 });
        RaderModels.Add(new RaderModel { ItemName = "客梯", Value = 30.00 });
        RaderModels.Add(new RaderModel { ItemName = "供水机", Value = 34.89 });
        RaderModels.Add(new RaderModel { ItemName = "喷淋水泵", Value = 69.59 });
        RaderModels.Add(new RaderModel { ItemName = "稳压设备", Value = 20 });

        #endregion

        #region 初始化人员缺岗信息
        StuffOutWorkList = new List<StuffOutWorkModel>();
        StuffOutWorkList.Add(new StuffOutWorkModel { StuffName = "张晓婷", Position = "技术员", OutWorkCount = 123 });
        StuffOutWorkList.Add(new StuffOutWorkModel { StuffName = "李晓", Position = "操作员", OutWorkCount = 23 });
        StuffOutWorkList.Add(new StuffOutWorkModel { StuffName = "王克俭", Position = "技术员", OutWorkCount = 134 });
        StuffOutWorkList.Add(new StuffOutWorkModel { StuffName = "陈家栋", Position = "统计员", OutWorkCount = 143 });
        StuffOutWorkList.Add(new StuffOutWorkModel { StuffName = "杨过", Position = "技术员", OutWorkCount = 12 });

        #endregion

        #region 初始化车间列表 
        WorkShopList = new List<WorkShopModel>();
        WorkShopList.Add(new WorkShopModel { WorkShopName = "贴片车间", WorkingCount = 32, WaitCount = 8, WrongCount = 4, StopCount = 0 });
        WorkShopList.Add(new WorkShopModel { WorkShopName = "封装车间", WorkingCount = 20, WaitCount = 8, WrongCount = 4, StopCount = 0 });
        WorkShopList.Add(new WorkShopModel { WorkShopName = "焊接车间", WorkingCount = 68, WaitCount = 8, WrongCount = 4, StopCount = 0 });
        WorkShopList.Add(new WorkShopModel { WorkShopName = "贴片车间", WorkingCount = 68, WaitCount = 8, WrongCount = 4, StopCount = 0 });

        #endregion
        #region 初始化机台列表
        MachineModels = new List<MachineModel>();
        Random random = new Random();
        for (int i = 0; i < 20; i++)
        {
            int plan = random.Next(100, 1000);//计划量 随机数
            int finished = random.Next(0, plan);//已完成量
            MachineModels.Add(new MachineModel
            {
                MachineName = "焊接机-" + (i + 1),
                FinishedCount = finished,
                PlanCount = plan,
                Status = "作业中",
                OrderNo = "H202212345678"
            });
        }
        #endregion
    }



    public UserControl MonitorUC
    {
        get
        {
            if (_userControl is null)
            {
                _userControl = new MonitorUC();
            }
            return _userControl;
        }
        set
        {
            _userControl = value;
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("MonitorUC"));
            }
        }
    }
    #region 时间
    public string? Time { get; } = DateTime.Now.ToString("HH:mm");

    public string? Date { get; } = DateTime.Now.ToString("yyyy-MM-dd");


    public string? Week { 
        
        get {

            int val=(int) DateTime.Now.DayOfWeek;
            string[] weeks = new string[7] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五日", "星期六" };
            return weeks[val];
        }
    }
    #endregion
    #region  计数 时间旁边数据
    public string _MachineCount = "0298";


    public string MachineCount
    {
        get { return _MachineCount; }

        set {
            _MachineCount = value;
            if (PropertyChanged != null) 
            {
                PropertyChanged(this, new PropertyChangedEventArgs("MachineCount"));
            }
        
        }

    }

    public string _ProductCount = "1324";


    public string ProductCount
    {
        get { return _ProductCount; }

        set
        {
            _ProductCount = value;
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("ProductCount"));
            }

        }

    }

    public string _BadCount = "1324";


    public string BadCount
    {
        get { return _BadCount; }

        set
        {
            _BadCount = value;
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("BadCount"));
            }

        }

    }
    #endregion
    #region 环境监控数据

    private List<EnviromentModel> _EnvironmentModels;

    public List<EnviromentModel> EnvironmentModels
    {
        get {

            return _EnvironmentModels;
        }
        set {
            _EnvironmentModels = value;
            if (PropertyChanged != null) 
            {
                PropertyChanged(this,new PropertyChangedEventArgs("EnviromentList"));
            }
        }
    
    }



    #endregion
    #region 报警属性

    /// <summary>
    /// 报警集合
    /// </summary>
    private List<AlarmModel> _AlarmList;

    /// <summary>
    /// 报警集合
    /// </summary>
    public List<AlarmModel> AlarmList
    {
        get { return _AlarmList; }
        set
        {
            _AlarmList = value;
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("AlarmList"));
            }
        }
    }
    #endregion


    #region 设备属性
    private List<DeviceModel> _DeviceModels;

    public List<DeviceModel> DeviceList
    {
        get { return _DeviceModels; }
        set { _DeviceModels = value;
            if (PropertyChanged != null) 
            {
                PropertyChanged(this,new PropertyChangedEventArgs("DeviceList"));
            }
        }
    }
    #endregion

    #region 雷达图属性

    private List<RaderModel> _RaderModels;
    public List<RaderModel> RaderModels
    {
        get { return _RaderModels; }
        set
        {
            _RaderModels = value;
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("RaderModels"));
            }
        }
    }
    #endregion


    #region 缺岗人员属性
    private List<StuffOutWorkModel> _StuffOutWorks;
    public List<StuffOutWorkModel> StuffOutWorkList
    {
        get { return _StuffOutWorks; }
        set
        {
            _StuffOutWorks = value;
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("StuffOutWorkList"));
            }
        }
    }
    #endregion


    #region 车间数据
    private List<WorkShopModel> _WorkShopModels;

    public List<WorkShopModel> WorkShopList
    {
        get { return _WorkShopModels; }
        set
        {
            _WorkShopModels = value;
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("WorkShopList"));
            }
        }
    }
    #endregion
   
    #region 机台属性集合
    private List<MachineModel> _MachineModels;

    public List<MachineModel> MachineModels
    {
        get { return _MachineModels; }
        set { _MachineModels = value; }
    }
    #endregion
}

